package com.iwhalecloud.bss.kite.cucc.service.attr.handler;

import com.iwhalecloud.bss.kite.common.util.KiteBeanUtils;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.dataservice.cache.AttrValueCache;
import com.iwhalecloud.bss.kite.dataservice.entity.AttrValue;
import com.iwhalecloud.bss.kite.manager.api.IOperateSceneInstService;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttrValue;
import com.iwhalecloud.bss.kite.manager.inst.KiteProdInst;
import com.iwhalecloud.bss.kite.service.attr.AttrData;
import com.iwhalecloud.bss.kite.service.attr.handler.AbstractAttrHandler;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Objects;

public class PaymentCycleAttrHandler extends AbstractAttrHandler<KiteProdInst, AttrData> {

    @Autowired
    IOperateSceneInstService operateSceneInstService;

    @Override
    public void before(KiteAttr attr, KiteProdInst inst, String value, AttrData data) {
        // 付费方式
       /* KiteAttr payMethodAttr = inst.getAttr("200000109");
        if (Objects.nonNull(payMethodAttr)) {

            //“付费方式”选择“后付费”时，付费周期只能选择“月付”；
            //“付费方式”选择“预付费”时，付费周期三个选项都可以选择；

           /** if (!KiteStringUtils.equals("100004663", value) && KiteStringUtils.equals("100001377", payMethodAttr.getValue())) {
                attr.setValue("");
                attr.setValueDesc("");
                attr.setDefaultValue("");
                operateSceneInstService.setAttr(data.getSceneInstId(), inst.getInstType(), inst.getInstId(), attr);
            } else if (KiteStringUtils.equals("100004663", value)) {
                List<AttrValue> attrValues = AttrValueCache.get(payMethodAttr.getAttrId());
                if (CollectionUtils.isNotEmpty(attrValues)) {
                    payMethodAttr.setAttrValues(KiteBeanUtils.copyPropsForList(attrValues, KiteAttrValue.class));
                    operateSceneInstService.setAttr(data.getSceneInstId(), inst.getInstType(), inst.getInstId(), payMethodAttr);
                }
            }
        } */
    }
}
